package com.qiangesoft.cloud.provider.controller;

import com.qiangesoft.cloud.provider.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@RequestMapping("/payment")
@RestController
public class PaymentController {

    @GetMapping("/add")
    public String add(String name) {
        System.out.println(name + "支付成功");
        return "8002:" + UUID.randomUUID().toString().replace("-", "");
    }

    @Autowired
    private PaymentService paymentService;

    @GetMapping("/addHystrix")
    public String addHystrix(String name) {
        System.out.println(name + "支付成功");
        return paymentService.addHystrix(name);
    }

    @Autowired
    private DiscoveryClient discoveryClient;

    @GetMapping("/discovery")
    public List<ServiceInstance> discovery() {
        List<String> services = discoveryClient.getServices();
        System.out.println(services);
        List<ServiceInstance> instances = discoveryClient.getInstances("provider-payment");
        System.out.println(instances.toString());
        return instances;
    }
}
